<template>
  <div id="ProvincialControl">
    <div class="homeTitle">全省宏观管控设置</div>
    <div class="titleName">债券交易</div>
    <table>
      <tr>
        <td>风险管控设置</td>
        <td><span>*</span>交易限制值(含填写值)</td>
        <td><span>*</span>省联社授权值(含填写值)</td>
        <td><span>*</span>预警提醒值(含填写值)</td>
      </tr>
      <tr v-for="(item, index) in risks" :key="index">
        <td>{{item.risk}}（全省）</td>
        <td><el-input v-model="item.transaction" placeholder="请输入百分占比" size="small"></el-input></td>
        <td><el-input v-model="item.authorization" placeholder="请输入百分占比" size="small"></el-input></td>
        <td><el-input v-model="item.warning" placeholder="请输入百分占比" size="small"></el-input></td>
      </tr>
     
    </table>
    <div class="titleName">债券回购交易</div>
    <table>
      <tr>
        <td>风险管控设置</td>
        <td><span>*</span>交易限制值(含填写值)</td>
        <td><span>*</span>省联社授权值(含填写值)</td>
        <td><span>*</span>预警提醒值(含填写值)</td>
      </tr>
      <tr v-for="(item, index) in hgrisks" :key="index">
        <td>{{item.risk}}（全省）</td>
        <td><el-input v-model="item.transaction" placeholder="请输入百分占比" size="small"></el-input></td>
        <td><el-input v-model="item.authorization" placeholder="请输入百分占比" size="small"></el-input></td>
        <td><el-input v-model="item.warning" placeholder="请输入百分占比" size="small"></el-input></td>
      </tr>
    </table>
    <div class="titleName">同业拆借交易、同业存单交易、存放同业交易</div>
    <table>
      <tr>
        <td>风险管控设置</td>
        <td><span>*</span>交易限制值(含填写值)</td>
        <td><span>*</span>省联社授权值(含填写值)</td>
        <td><span>*</span>预警提醒值(含填写值)</td>
      </tr>
       <tr v-for="(item, index) in tyrisks" :key="index">
        <td>{{item.risk}}（全省）（与同业存单、存放同业合并控制）</td>
        <td><el-input v-model="item.transaction" placeholder="请输入百分占比" size="small"></el-input></td>
        <td><el-input v-model="item.authorization" placeholder="请输入百分占比" size="small"></el-input></td>
        <td><el-input v-model="item.warning" placeholder="请输入百分占比" size="small"></el-input></td>
      </tr>
    </table>
    <!-- <div class="titleName">债券借贷交易</div>
    <table>
      <tr>
        <td>风险管控设置</td>
        <td><span>*</span>交易限制值(含填写值)</td>
        <td><span>*</span>省联社授权值(含填写值)</td>
        <td><span>*</span>预警提醒值(含填写值)</td>
      </tr>
  
       <tr v-for="(item, index) in jdrisks" :key="index">
        <td>{{item.risk}}（全省）</td>
        <td><el-input v-model="item.transaction" placeholder="请输入百分占比" size="small"></el-input></td>
        <td><el-input v-model="item.authorization" placeholder="请输入百分占比" size="small"></el-input></td>
        <td><el-input v-model="item.warning" placeholder="请输入百分占比" size="small"></el-input></td>
      </tr>
    </table> -->
    <div class="titleName">理财产品交易</div>
    <table>
      <tr>
        <td>风险管控设置</td>
        <td><span>*</span>交易限制值(含填写值)</td>
        <td><span>*</span>省联社授权值(含填写值)</td>
        <td><span>*</span>预警提醒值(含填写值)</td>
      </tr>
     <tr v-for="(item, index) in lcrisks" :key="index">
        <td>{{item.risk}}（全省）</td>
        <td><el-input v-model="item.transaction" placeholder="请输入百分占比" size="small"></el-input></td>
        <td><el-input v-model="item.authorization" placeholder="请输入百分占比" size="small"></el-input></td>
        <td><el-input v-model="item.warning" placeholder="请输入百分占比" size="small"></el-input></td>
      </tr>
    </table>
    <div class="btn">
      <el-button type="primary" @click="submitPost" size="small">提交</el-button>
      <el-button type="primary" size="small">取消</el-button>
    </div>
  </div>
</template>

<script>
export default {
  name: 'ProvincialControl',
  data () {
    return {
      tel:'',
      risks: [
        {risk: '信用债集中度', transaction: '', authorization: '', warning: '', model: '债券交易'},
        // {risk: '信用债地市占比', transaction: '', authorization: '', warning: '', model: '债券交易'},
        // {risk: '信用债行业分类占比', transaction: '', authorization: '', warning: '', model: '债券交易'}
      ],
      hgrisks: [
        {risk: '单一客户集中度', transaction: '', authorization: '', warning: '', model: '债券回购交易'}
      ],
      tyrisks: [
        {risk: '交易集中度', transaction: '', authorization: '', warning: '', model: '同业相关'}
      ],
      lcrisks: [
          {risk: '交易集中度', transaction: '', authorization: '', warning: '', model: '理财产品交易'}
      ],
      jdrisks: [
         {risk: '单一客户集中度', transaction: '', authorization: '', warning: '', model: '债券借贷交易'}
      ]
    };
  },
  mounted() {
    this.getDetails()
  },
  methods: {
    submitPost() {
          let param = []
          let params = []
          /**债券交易和理财产品交易必填 */
          if(this.risks[0].transaction != '') {
            params = params.concat(this.risks)
          }
          if(this.tyrisks[0].transaction != '') {
            params = params.concat(this.tyrisks)
          }
          if(this.lcrisks[0].transaction != '') {
            params = params.concat(this.lcrisks)
          }
          if(this.hgrisks[0].transaction != '') {
            params = params.concat(this.hgrisks)
          }
          // if(this.jdrisks[0].transaction != '') {
          //   params = params.concat(this.jdrisks)
          // }
            this.axios.post('provincial/addOrUpdate', params).then((res) => {
              this.$message({
                type: 'success',
                message: '提交成功'
              })
              this.getDetails()
            })
    },
    getDetails() {
      this.axios.get('provincial/selectOne').then(res => {
          let data = res.data.data
             data.forEach((item, index) => {
              if(item.model == '债券交易'){
                
                let detaliList = item.detaliList
                
                this.risks = []
                detaliList.forEach(item => {
                  item.model = '债券交易'
                  
                  this.risks.push(item)
                })
                console.log(this.risks)
              }
              if(item.model == '债券回购交易'){
       
                let detaliList = item.detaliList
                detaliList.forEach(item => {
                  item.model = '债券回购交易'
                  this.hgrisks = []
                  this.hgrisks.push(item)
                })
              }
              
              if(item.model == '同业相关'){
                 let detaliList = item.detaliList
                detaliList.forEach(item => {
                  item.model = '同业相关'
                  this.tyrisks = []
                  this.tyrisks.push(item)
                })
              }

              if(item.model == '债券借贷交易'){
                let detaliList = item.detaliList
                detaliList.forEach(item => {
                  item.model = '债券借贷交易'
                  this.jdrisks = []
                  this.jdrisks.push(item)
                })
              }
              if(item.model == '理财产品交易'){
                let detaliList = item.detaliList
                detaliList.forEach(item => {
                  item.model = '理财产品交易'
                  this.lcrisks = []
                  this.lcrisks.push(item)
                })
              }
          })
      })
    }
  }
};
</script>

<style lang="scss">
  #ProvincialControl {
    padding-bottom: 20px;
    .titleName {
      height: 50px;
      background: white;
      padding-left: 20px;
      line-height: 50px;
      margin-top: 20px;
    }
        table {
      margin: 15px 0;
      width: 100%;
      tr {
        &:first-child {
         td {
           background-color: rgba(58, 58, 58, 0.4);
           color: white;
           padding: 10px 15px;
           text-align: center;
           span {
             color: red;
           }
         } 
        }
        td {
          background-color: rgba(58, 58, 58, 0.3);
          padding: 10px 10px;
          text-align: center;
          color: white;
          .el-input__inner{
            background: transparent;
            color:white;
            border: 0
          }
        }
      }
    }
    .btn {
      margin-top: 20px;
      text-align: center;
      .el-button {
        margin-right: 20px;
      }
    }
  }
</style>
